package com.springboot.controller;

import com.github.pagehelper.PageInfo;
import com.springboot.entity.User;
import com.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by megagao on 2018/7/16.
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @PostMapping("/add")
    public int addUser(User user){
        return userService.addUser(user);
    }

//    @ResponseBody
//    @GetMapping("/all")
    @RequestMapping("/all")
    public String findAllUser(Model model,
            @RequestParam(name = "pageNum", required = false, defaultValue = "1")
                    int pageNum,
            @RequestParam(name = "pageSize", required = false, defaultValue = "10")
                    int pageSize){
        PageInfo<User> userPageInfo = userService.findAllUser(pageNum,pageSize);
        List<User> users = userPageInfo.getList();
        model.addAttribute("users",users);
        return "hello";
    }
}